package com.gan.simple_init.quartz.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gan.simple_init.common.base.PageRequest;
import com.gan.simple_init.common.exception.BusinessException;
import com.gan.simple_init.quartz.model.SysJob;
import com.gan.simple_init.quartz.model.dto.SysJobDTO;


/**
* @author gbw
* @description 针对表【sys_job(定时任务表)】的数据库操作Service
* @createDate 2023-08-20 15:40:38
*/
public interface SysJobService extends IService<SysJob> {


    /**
     * 根据 id 获取任务信息
     * @param id
     * @return
     * @throws BusinessException
     */
    SysJob get(Long id) throws BusinessException;

    /**
     * 分页获取任务信息
     * @param pageRequest
     * @return
     * @throws BusinessException
     */
    Page<SysJobDTO> listSysJob(PageRequest pageRequest) throws BusinessException;

    /**
     * 保存任务
     * @param sysJob
     * @return
     * @throws BusinessException
     */
    boolean save(SysJob sysJob) throws BusinessException ;

    /**
     * 逻辑删除某个任务
     * @param id
     * @return
     * @throws BusinessException
     */
    Integer remove(Long id) throws BusinessException ;

    /**
     * 批量删除任务
     * @param ids
     * @return
     * @throws BusinessException
     */
    boolean removeBatch(Long[] ids) throws BusinessException ;

    /**
     * 批量恢复任务
     * @param ids
     * @return
     * @throws BusinessException
     */
    boolean resumeBatch(Long[] ids) throws BusinessException;

    /**
     * 批量暂停任务
     * @param ids
     * @return
     * @throws BusinessException
     */
    boolean pauseBatch(Long[] ids) throws BusinessException;


    /**
     * 初始化任务
     * @throws BusinessException
     */
    void initSchedule() throws BusinessException ;

    /**
     * 修改任务状态
     * @param jobId
     * @param isValid
     * @throws BusinessException
     */
    void changeStatus(Long jobId, String isValid) throws BusinessException ;

    /**
     * 修改 cron 表达式
     * @param jobId
     * @param cron
     * @throws BusinessException
     */
    void updateCron(Long jobId, String cron) throws BusinessException;

    /**
     * 运行任务
     * @param scheduleJob
     * @throws BusinessException
     */
    void run(SysJob scheduleJob) throws BusinessException ;

    /**
     * 校验任务参数
     * @param sysJob
     * @return
     */
    boolean validJob(SysJob sysJob);
}
